home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
183_01
/
comsup.doc
< prev
next >
Wrap
Text File
|
1984-06-21
|
17KB
|
581 lines
=================================================
= =
= Communications support for DeSmet C compiler =
= =
=================================================
Written by Tom Poindexter (70040,1223), March 1984
Acknowledgements: Vern Buerg - for an example of comm support for
the Lattice C compiler. (DRIVER.ASM)
Curt Klinsing - the author listed in DRIVER.ASM
Earl Terwilliger Jr. - referring me to the PC Tech
Journal series on 8088 interrupts
Chris Dunford - author of the 2 part series in PC Tech
Journal (12/83 & 1/84).
=========
The following files constitute the communication support routines.
COMMSUPP.C - The actual C interface routines.
COMMASM.A - Internal assembler routines used by commsupp.c.
COMMSUPP.H - An #include file containing declares and defines for
an application program using commsupp.c.
COMMSUPP.DOC - This documentation.
-------------
COMMTERM.C - Optional, an example C communications program using
commsupp.c
=========
COMMSUPP provides interrupt driven buffered communication support for the
DeSmet C compiler. Features: XON/XOFF support, two ports active
concurrently, modem break signal generation, status reporting, and
event trapping.
Most of the routines are written in C so that it may be possible to
port these routines to another compiler. The assembler language routines
are coded in DeSmet ASM88 syntax, which is somewhat different than the
IBM Macro Assembler syntax.
DeSmet library functions that may or may not be available on other
compilers are:
_lmove(num_bytes,source_offset,source_segment,target_offset,target_segment);
Performs a memory move using REP MOVSB so that overlapping moves are
handled correctly (processor direction flag set correctly).
_move(num_bytes,source_offset,target_offset);
Similiar to _lmove, except that the move is within the C data segment.
c_ds = _showds();
Returns the C data segment.
c_cs = _showcs();
Returns the C program segment.
ptr = malloc(num_bytes);
Allocate a specific number of bytes in memory and return a pointer
to the area.
The following functions are not available in DeSmet C, but may or may not
be included in other compilers. These routines are in COMMASM.A:
struct { int ax,bx,cx,dx,si,di,ds,es;} in_regs,out_regs;
flags = sysint (interrupt, &in_regs, &out_regs);
Call a system interrupt routine, passing and returning register values.
value = inb(hardware_port);
Input a byte value from a hardware port address.
outb(hardware_port,value);
Output a byte value to a hardware port address.
cli();
Disable system interrupts (CLI).
sti();
Enable system interrupts (STI);
DeSmet C compiler use
=====================
1. Compile COMMSUPP.C with C88
A>c88 commsupp
2. Assemble COMMASM.A with ASM88
A>asm88 commasm
3. If you maintain your own library, use LIB88 to add commsupp and commasm
A>lib88 commasm commsupp -oyourlib
4. Create and compile your program. #include "commsupp.h".
A>c88 yourprog
5. Bind your program with your library (as in #3) or with the object
modules alone.
A>bind yourprog (your-other-modules) commsupp commasm w/o private lib
A>bind yourprog yourlib.s w/ private lib
Description of routines:
========================
init_com - Initializes the serial port, enables and sets interrupt vectors,
sets communication parameters (baud, parity, data length,
stop bits), and allocates a receive buffer.
Parms:
port: 1 = com1:, 2 = com2:
baud: 110, 150, 300, 450, 600, 1200, 2400, 4800, 9600
parity: 0 = none, 1 = odd, 2 = even, 3 = mark, 4 = space
data: 5, 6, 7, 8
stop: 1, 2
buff_len: length of receive buffer up to 32767 bytes
Returns:
ERROR (-1): comm port not available or invalid parm
TRUE (1): ok
Example:
int port, baud, parity, data, stop, buff_len;
port = 1;
baud = 300;
parity = 0;
data = 8;
stop = 1;
buff_len = 1024;
if (init_com(port,baud,parity,data,stop,buff_len) == ERROR)
puts("\nComm port initialzation failed.\n");
Notes:
See defines for parity values in COMMSUPP.H. This function sets the
8250 modem controller chip and the 8259 interrupt controller chip.
Also, this routine "pokes" the value of the C data segment into
the interrupt handler routine so that no matter where the
interrupt occurs, the interrupt handler will have access to the
C data segment.
See the PC Tech Journal (12/83 & 1/84) for details on the
interrupt controller.
=========
uninit_com - Disables interrupts, flushes buffer. Optionally leaves serial
port open.
Parms:
port: 1 = com1:, 2 = com2:
lv_open: TRUE (1) = leave serial open (DTR enabled), FALSE (0) = close
serial port (drop DTR).
Returns:
ERROR (-1): comm port never intialized or invalid port number.
TRUE (1): ok
Example:
int port, lv_open;
port = 1;
lv_open = TRUE;
uninit_com(port,lv_open);
puts("\n\nProgram terminating.......Comm port left open.\n\n");
Notes:
It is VERY important that this function is successfully completed
prior to the termination of the user program. Otherwise, any incoming
chars will trigger the interrupt and control will pass to the interrupt
handler address, whether or not there is a valid routine to process
the interrupt.
=========
send_brk - Send a break signal to the specified port. 1/2 second of mark
signal is generated.
Parms:
Port: 1 = com1:, 2 = com2:
Returns:
ERROR (-1): comm port never intialized or invalid port number.
TRUE (1): ok
Example:
int port;
port = 1;
send_brk(port);
Notes:
See this routine in commsupp.c on using the SYSINT function. The
time-of-day interrupt (documented in the tech reference) is invoked
to return the current time-of-day tick count. The effect of the
routine is a delay for a specified time that is independent
of processor speed.
=========
set_xoff - Enables or disables the XON/XOFF protocol. See companion functions
recd_xoff and sent_xoff. If enabled, an XOFF received will set
a flag which can be parsed with the recd_xoff function. The user
program must check recd_xoff to suspend transmission, i.e.,
outp_char and outp_strn are not automatically suspended. Also, if
the receive buffer becomes 75% full, an XOFF is sent to the remote
computer, and a flag is set, which can be parsed with sent_xoff.
Parms:
port: 1 = com1:, 2 = com2:
state: TRUE (1) = XON/XOFF enabled, FALSE (0) = XON,XOFF disabled
Returns:
ERROR (-1): comm port never intialized or invalid port number.
TRUE (1): ok
Example:
int port, state;
port = 1;
puts("\nDo you want XON/XOFF enabled (y/n) ? ");
state = (getchar() == 'y') ? TRUE : FALSE;
set_xoff(port,state);
Notes:
XON/XOFF should be disabled anytime binary transmissions are performed,
i.e., all 8 bits significant. When XON/XOFF is disabled, there is no
mechansism to prevent or report buffer overrun. In this case the
user program should be alert to the number of bytes in the buffer using
the inp_cnt function.
=========
recd_xoff - Report if an XOFF character has been received. If TRUE, then
also reset the recd_xoff flag to FALSE.
Parms:
port: 1 = com1:, 2 = com2:
Returns:
ERROR (-1): comm port never intialized or invalid port number.
TRUE (1): XOFF has been received
FALSE (0): XOFF has not